import 'package:aichat_flutter_wallet/module_common/utils/colors.dart';
import 'package:aichat_flutter_wallet/module_common/widgets/image/public_image.dart';
import 'package:aichat_flutter_wallet/module_common/widgets/token_widget/token_logo.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lib_database/lib_database.dart';
import 'package:lib_util/utils/utils.dart';

class TokenWidget extends StatelessWidget {
  final Token? token;
  final bool select;
  final GestureTapCallback? onTap;
  final GestureTapCallback? onLongPress;

  const TokenWidget({super.key, required this.token, this.onTap, this.onLongPress, this.select = false});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 60.w,
      padding: EdgeInsets.symmetric(horizontal: 20.w),
      child: token == null
          ? Container()
          : InkWell(
              onTap: onTap,
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Expanded(
                    child: Row(
                      children: [
                        Stack(
                          clipBehavior: Clip.none,
                          children: [
                            ClipRRect(
                              borderRadius: BorderRadius.circular(20.w),
                              child: TokenLogo(
                                token: token!,
                                size: 40.w,
                              ),
                            ),
                            Visibility(
                                visible: token?.contractType != TokenType.native.name,
                                child: Positioned(
                                  right: -3.w,
                                  bottom: -1.w,
                                  child: ClipRRect(
                                    borderRadius: BorderRadius.circular(16.w),
                                    child: PublicImage(width: 16.w, height: 16.w, image: token!.getChain()!.logo),
                                  ),
                                ))
                          ],
                        ),
                        SizedBox(
                          width: 6,
                        ),
                        Text(
                          token!.symbol,
                          style: TextStyle(color: AppColors.c_333333, fontWeight: FontWeight.w500, fontSize: 14.sp),
                        )
                      ],
                    ),
                  ),
                  Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.end,
                    children: [
                      Text(
                        null == token!.balance
                            ? '0.00'
                            : Utils.formatStringBalance(token!.balance!,
                                fractionDigits: Config.balanceFixedNum, trimDecimalZero: true),
                        style: TextStyle(color: AppColors.c_333333, fontWeight: FontWeight.bold, fontSize: 16.sp),
                      ),
                      SizedBox(
                        height: 4.w,
                      ),
                      Text(
                        (null == token!.priceusd ||
                                token!.priceusd!.isEmpty ||
                                null == token!.balance ||
                                token!.balance!.isEmpty)
                            ? '\$0.00'
                            : '\$${Utils.formatStringBalance((double.parse(token!.balance!) * double.parse(token!.priceusd!)).toString(), fractionDigits: Config.priceNum, trimDecimalZero: true)}',
                        style: TextStyle(color: AppColors.c_BEBDCA, fontWeight: FontWeight.bold, fontSize: 12.sp),
                      ),
                    ],
                  )
                ],
              ),
            ),
    );
  }
}
